package Test;

import java.util.Date;

import junit.framework.TestCase;

import CtrLayer.PaintingCtr;
import CtrLayer.ServiceCtr;
import DataLayer.Model.Kunde;
import DataLayer.Model.Service;

public class testPaintingCtr extends TestCase
{
	public PaintingCtr pCtr;
	public ServiceCtr sCtr;
	private Service service1;
	private Service service2;
	private Service service3;
	private String fornavn;

	public void setUp() throws Exception
	{
		pCtr = PaintingCtr.getInstance();
		sCtr = new ServiceCtr();
		service1 = new Service("Flames of War test", "Tank", "Standard", 75, true);
		service2 = new Service("40K test", "Drop pod", "Tabletop", 250, true);
		service3 = new Service("40K test", "Standard model", "Tabletop", 40, true);
		fornavn = "Dennis";
	}

	public void tearDown() throws Exception
	{
		pCtr = null;
		sCtr = null;
		service1 = null;
		service2 = null;
		service3 = null;
	}

	// Normal use-case scenario
	public void testStartPaintingOrdre()
	{
		// 1
		pCtr.startPaintingOrdre();
		// 2
		pCtr.addService(1, service1);
		// 3
		assertEquals(75.0, pCtr.getOrdre().getTotal());
		//4
		pCtr.addService(1, service2);
		pCtr.addService(1, service3);
		assertEquals(75.0+250.0+40.0, pCtr.getOrdre().getTotal());
		long leveringsDato = new Date().getTime();
		pCtr.getOrdre().setLeveringsDato(leveringsDato);
		// 6
		pCtr.getOrdre().setKunde(new Kunde());
		pCtr.getOrdre().getKunde().setFornavn(fornavn);
		// 8
		assertEquals(fornavn, pCtr.getOrdre().getKunde().getFornavn());
		// Part 8-19 skipped
	}


	public void testSetPaintingOrdre()
	{
		// Expecting null from this nonexistent id
		pCtr.setPaintingOrdre(-1);
		assertNull(pCtr.getOrdre());
	}

	public void testSetPaintingKunde()
	{
		pCtr.startPaintingOrdre();
		Kunde k = new Kunde();
		k.setFornavn(fornavn);
		pCtr.getOrdre().setKunde(k);
		assertEquals(fornavn, pCtr.getOrdre().getKunde().getFornavn());
		assertNull(pCtr.getOrdre().getKunde().getEfternavn());
	}


	public void testAddService()
	{
		pCtr.startPaintingOrdre();
		pCtr.addService(10, service1);
		pCtr.addService(11, service2);
		pCtr.addService(12, service3);
		assertNotNull(pCtr.getAllDelOrdre());
		assertEquals(3, pCtr.getAllDelOrdre().size());
	}


	public void testSetButikOrdreKunde()
	{
		pCtr.startPaintingOrdre();
		Kunde k = new Kunde();
		k.setFornavn(fornavn);
		pCtr.getOrdre().setKunde(k);
		assertEquals(fornavn, pCtr.getOrdre().getKunde().getFornavn());
		assertNull(pCtr.getOrdre().getKunde().getEfternavn());
	}


	public void testUpdateProduktAntal() throws Exception
	{
		pCtr.startPaintingOrdre();
		pCtr.addService(10, service1);
		pCtr.addService(11, service2);
		pCtr.addService(12, service3);
		// Check total, without update 3980.0, with 1230.0;
		pCtr.updateServiceAntal(-2, 11, -2);
		assertEquals(1230.0, pCtr.getOrdre().getTotal());
		
	}


	public void removeProdukt()
	{
		pCtr.startPaintingOrdre();
		pCtr.addService(10, service1);
		pCtr.addService(11, service2);
		pCtr.addService(12, service3);
		pCtr.removeServiceOrEkstra(-2, service2.getMalestandard());
		assertEquals(2, pCtr.getAllDelOrdre().size());
	}
}
